﻿using System;
using System.Windows;

namespace ZOIL.Framework.Presentation
{
        /// <summary>
        /// Defines a position in information space.
        /// </summary>
        public struct ZLandscapePosition
        {
            /// <summary>
            /// Defines depth.
            /// 1.0 means the entire landscape fits on the screen, everything
            /// above that value zooms into the landscape.
            /// </summary>
            public double Zoom;

            /// <summary>
            /// X, Y offset for the upper left corner of the screen.
            /// </summary>
            public Point Pan;

            /// <summary>
            /// 
            /// </summary>
            public bool IsValid
            {
                get
                {
                    return !(Double.IsInfinity(Zoom))
                        && !(Double.IsNaN(Pan.X))
                        && !(Double.IsNaN(Pan.Y));
                }
            }

            /// <summary>
            /// 
            /// </summary>
            /// <param name="zoom"></param>
            /// <param name="pan"></param>
            public ZLandscapePosition(double zoom, Point pan)
            {
                this.Zoom = zoom;
                this.Pan = pan;
            }

            /// <summary>
            /// 
            /// </summary>
            /// <param name="position1"></param>
            /// <param name="position2"></param>
            /// <returns></returns>
            public static bool operator ==(ZLandscapePosition position1, ZLandscapePosition position2)
            {
                return (Math.Abs(position1.Zoom - position2.Zoom)
                    + Math.Abs(position1.Pan.X - position2.Pan.X)
                    + Math.Abs(position1.Pan.Y - position2.Pan.Y) < 0.001);
            }

            /// <summary>
            /// 
            /// </summary>
            /// <param name="position1"></param>
            /// <param name="position2"></param>
            /// <returns></returns>
            public static bool operator !=(ZLandscapePosition position1, ZLandscapePosition position2)
            {
                return !(position1 == position2);
            }

            /// <summary>
            /// 
            /// </summary>
            /// <param name="position"></param>
            /// <returns></returns>
            public override bool Equals(object position)
            {
                return this == (ZLandscapePosition)position;
            }

            /// <summary>
            /// 
            /// </summary>
            /// <returns></returns>
            public override int GetHashCode()
            {
                return (int)Zoom + (int)Pan.X + (int)Pan.Y;
            }
        }


    }

